package com.heima.article.feign;

import com.heima.apis.article.IArticleClient;
import com.heima.article.service.ApArticleService;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.comment.dtos.CommentPageDto;
import com.heima.model.comment.dtos.StatusCommentDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmNewsStatisticsDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@Slf4j
@RestController
public class ArticleClient implements IArticleClient {

    @Autowired
    private ApArticleService apArticleService;

    @Override
    @PostMapping("/api/v1/article/save")
    public ResponseResult saveArticle(@RequestBody ArticleDto dto) {
        log.info("保存或修改文章, : {}",dto);
        return apArticleService.saveArticle(dto);
    }

    /**
     * 查看文章统计
     * @param wmUserId
     * @param beginDate
     * @param endDate
     * @return
     */
    @GetMapping("/api/v1/article/queryLikesAndConllections")
    public ResponseResult getNewsDimension(@RequestParam("wmUserId") Integer wmUserId, @RequestParam("beginDate") Date beginDate, @RequestParam("endDate") Date endDate) {
        return apArticleService.getNewsDimension(wmUserId,beginDate,endDate);
    }

    @PostMapping("/api/v1/article/newPage")
    @Override
    public PageResponseResult getNewsPage(@RequestBody WmNewsStatisticsDto dto) {
        return apArticleService.getNewsPage(dto);
    }

    @PostMapping("/api/v1/comment/manage/find_news_comments")
    public ResponseResult showListComment(@RequestBody CommentPageDto dto) {
        return apArticleService.showListComment(dto);
    }

    @Override
    @PostMapping("/api/v1/comment/manage/update_comment_status")
    public ResponseResult updateStatusComment(@RequestBody StatusCommentDto dto) {
        return apArticleService.updateStatusComment(dto);
    }

    @GetMapping("/api/v1/comment/manage/get_is_comment")
    public Boolean getIsComment(@RequestParam("articleId") Long articleId){
        return apArticleService.getIsComment(articleId);
    }

}